<template>
	<view>
		<view class="sou">
			<input class="weui-input" auto-focus placeholder="搜索" v-model="word" @confirm="search"/>
		</view>
		<view>
			历史记录
		</view>
		<view>
			<van-tag
			v-for="(item,index) in lsir"
			:key="index"
			
			  closeable
			  size="medium"
			  type="primary"
			  id="primary"
			  @close="onClose(index)"
			>
			{{item.name}}
			</van-tag>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				word:'',
				lsir:[]
				
				
			}
		},
		methods: {
			onClose(index) {
			    this.lsir.splice(index,1)
				
			  },
			search(){
				if(this.word==""){
					return false
				}
				var index=this.lsir.findIndex(item=>{
					return item.name==this.word
				})
				if(index!=-1){
					this.lsir.splice(index,1)
				}
				if(this.lsir.length>3){
					this.lsir.pop()
				}
				var obj={name:this.word}
				this.lsir.unshift(obj)
				wx.setStorageSync("his",this.lsir)
				wx.navigateTo({
					url:"/pages/lishi/lishi?id="+this.word
				})
				this.word=''
				
			}
		},
		onLoad() {
			this.lsir=wx.getStorageSync("his")||[]
		},
		watch:{
			lisr:{
				handler(val){
					wx.setStorageSync("his",this.lsir)
				},
				deep:true
			}
		},
		
	}
</script>

<style>
.sou{
	width: 100%;
	height: 100rpx;
	background-color:#2049cc;
	display: flex;
	/* flex-direction: row; */
	/* align-content: stretch; */
	justify-content: center;
}
.weui-input{
	width: 85%;
	height: 70rpx;
	padding-left: 50rpx;
	border-radius: 20rpx;
	background-color: #ffffff;
	margin-top: 15rpx;
}
van-tag{
	margin-left: 20rpx;
}
</style>
